package com.example.demo.school.controllers;

import com.example.demo.school.models.StType;
import com.example.demo.school.repositories.StStudentRepository;
import com.example.demo.school.repositories.StTypeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Optional;

/**
 * @Author Jack
 * @Package com.example.demo.school.controllers
 * @Date 4/10/2024 5:16 PM
 * @description:
 */

@Controller
public class PageController {

    @Autowired
    StTypeRepository stTypeRepository;

    @Autowired
    StStudentRepository studentRepository;

    @RequestMapping(value = "/")
    public String index(){
        return "./index";
    }

    @RequestMapping(value = "/student/list")
    public String stuList(){
        return "./student/list";
    }

    @RequestMapping(value = "/student/edit/{id}")
    public String stuEdit(@PathVariable Long id, Model model){
        model.addAttribute("student",studentRepository.findById(id).get());
        return "./student/edit";
    }
    @RequestMapping(value = "/student/add")
    public String stuAdd(){
        return "./student/add";
    }
    @RequestMapping(value = "/type/list")
    public String typList(){
        return "./type/list";
    }

    @RequestMapping(value = "/type/edit/{id}")
    public String typEdit(@PathVariable Long id, Model model){
        model.addAttribute("type",stTypeRepository.findById(id).get());
        return "./type/edit";
    }

    @RequestMapping(value = "/type/add")
    public String typAdd(){
        return "./type/add";
    }

}
